//
//  DMInAppVerifyManager.h
//  DMPolymerizeSDK
//
//  Created by YeJary on 2025/4/29.
//

#import <Foundation/Foundation.h>
#import <StoreKit/StoreKit.h>
#import "../../AD/Common/DMAdDelegate.h"
#import "../../Core/DMLifecycle/Types/DMLifecycleTypes.h"

NS_ASSUME_NONNULL_BEGIN

@interface DMInAppVerifyManager : NSObject

@property (nonatomic, weak) id<DMAdDelegate> delegate;

+ (instancetype)sharedManager;

/// 上传订单信息到服务器进行核销校验
- (void)verifyTransactionWithTransactionId:(NSString *)transactionId
                                  productId:(NSString *)productId
                                       uuid:(NSString *)uuid
                                   envType:(NSString *)envType;
/// App启动时，自动尝试补单
- (void)autoRetryPendingOrders;

- (BOOL)isPendingOrderTransactionId:(NSString *)transactionId;

- (void)clearVerifiedTransactions;

/// 核销指定的内购订单
/// @param originalTransactionId 原始交易ID
/// @param successCallback 成功回调
/// @param failureCallback 失败回调
- (void)acknowledgeInAppPurchaseWithOriginal_transaction_id:(NSString *)originalTransactionId
                                            successCallback:(DMInAppPurchaseSuccessCallback)successCallback
                                            failureCallback:(DMInAppPurchaseFailureCallback)failureCallback;

/// 获取未核销订单列表
/// @param successCallback 成功回调，返回未核销订单数组
/// @param failureCallback 失败回调
- (void)fetchUnacknowledgedOrdersWithSuccess:(DMUnacknowledgedOrdersCallback)successCallback
                                     failure:(DMInAppPurchaseFailureCallback)failureCallback;

/// 校验内购收据
/// @param appId 应用ID
/// @param receiptData 收据数据
/// @param successCallback 成功回调
/// @param failureCallback 失败回调
- (void)verifyInAppReceiptWithAppId:(NSString *)appId
                        receiptData:(NSData *)receiptData
                    successCallback:(DMInAppPurchaseSuccessCallback)successCallback
                    failureCallback:(DMInAppPurchaseFailureCallback)failureCallback;

@end

NS_ASSUME_NONNULL_END
